<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title></title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/font-awesome.css" rel="stylesheet">
    <link href="/css/datatables.min.css" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <script src="/js/jquery-3.1.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/vue.js"></script>
</head>
<body style="background-color:whitesmoke">
<div id="admin">
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>上菜管理</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="javascript:void(0);">上菜管理</a>
                </li>

            </ol>
        </div>
    </div>


    <div class="wrapper wrapper-content animated fadeInRight">
        <!-- 搜索功能  -->
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row">
                <form role="form" class="form-horizontal">
                    <div class="form-group">

                        <label class=" col-sm-1 control-label">桌号</label>
                        <div class=" col-sm-2">
                            <input type="text" id="num" class="form-control" v-model="tablessId" placeholder="请输入桌号" @keyup="caiNum">
                        </div>

                        <label class=" col-sm-1 control-label">状态</label>
                        <div class=" col-sm-2">
                            <select v-model="menu.menuState">
                                <option value="-1">全部</option>
                                <option value="1">已上菜</option>
                                <option value="0">未上菜</option>
                            </select>
                        </div>

                        <div>
                            <button class="btn btn-primary btn-sm" type="button"  @click="loadData()"><span class="glyphicon glyphicon-zoom-in" ></span> 查询</button>
                        </div>
                    </div>
                </form>

            </div>

        </div>
        <div class="row">
            <div class="col-lg-12">

                <div class="ibox float-e-margins">

                    <div class="ibox-content">

                        <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="15">
                            <thead>
                            <tr>

                                <th data-toggle="true">编号</th>
                                <th data-hide="phone">菜名</th>
                                <th data-hide="phone">数量</th>
                                <th data-hide="phone">桌号</th>
                                <th data-hide="phone">状态</th>
                                <th  data-sort-ignore="true">操作</th>

                            </tr>
                            </thead>
                            <tbody>
                            <tr v-for="(x,index) in list">
                                <td>{{index+1}}</td>
                                <td>{{x.menuName}}</td>
                                <td>{{x.menNum}}</td>
                                <td>{{x.tablessId}}</td>
                                <td>
                                    <span v-if="x.menuState == 0" style="color:red;">未上菜</span>
                                    <span v-else style="color:blue;">已上菜</span>
                                </td>
                                <td>
                                    <button class="btn-primary btn btn-sm" @click="shangcai(x)" ><span class="glyphicon glyphicon-tag"></span>上菜</button>
                                    <button class="btn-primary btn btn-danger btn-sm"  @click="deleteData(x)" ><span class="glyphicon glyphicon-trash"></span> 删除</button>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <span id="infos" th:text="${info}" hidden="hidden"></span>
</div>
</body>

<script>

    new Vue({
        el:"#admin",
        data:{
            list:[],
            tablessId:"",
            menu:{ //查询对象
                categoryName:"",    //类别
                tablessId:-1,    //桌号
                menNum:1,  //菜品数量
                category:{
                    categoryName:"",    //部门
                    categoryId:"",  //种类编号
                },
                menuName:"",    //菜品名称
                menuState:-1    //菜品状态
            }
        },
        methods: {
            loadData: function () {
                var tests = $("#infos").text();
                var self = this;
                self.menu.categoryName = tests;
                if(self.tablessId != ""){
                    self.menu.tablessId = self.tablessId;
                }else {
                    self.menu.tablessId = -1;
                }
                $.ajax({
                    url:"http://192.168.7.36:2021/login-caipinguanli/menu/selectRedis",//请求地址
                    type: "post",
                    data:JSON.stringify(self.menu),
                    contentType:"application/json",
                    dataType: "json",//返回的数据类型
                    success: function (data) {
                        self.list = data.list;
                        console.log(self.list)
                        self.tablessId = "";
                    }
                })
            },
            caiNum: function () {
                //定义正则表达式对象
                var dd = /\D/;   //非数字
                var one = $("#num");   //JQuery如何获得拼接id时，基本都是使用了 eval（）<方法：
                var id = one.val();
                if (dd.test(id)) {
                    one.val(1);
                    this.tablessId = 1;
                }
            },
            saveAdmin:function () {//保存
                console.log(this.menu)
                var url="";
                if(this.title=="类型修改"){
                    url="http://192.168.7.36:2021/login-caipinguanli/menu/update";
                }else{
                    url="http://192.168.7.36:2021/login-caipinguanli/menu/add";
                }
                var self = this;
                console.log(url);
                $.ajax({
                    url:url,
                    type:"post",
                    data:JSON.stringify(self.menu),
                    contentType:"application/json",
                    dataType:"json",
                    success:function (data) {
                        console.log(data);
                        alert(data.info);
                        if(data.info=="保存成功"){
                            //关闭模态框
                            self.closeWin();
                            //刷新
                            self.loadData();
                        }
                    }
                })

            },
            shangcai:function(data){
                var self = this;
                self.menu = data;
                $.ajax({
                    url:"http://192.168.7.36:2021/login-caipinguanli/menu/caiUp",
                    type:"post",
                    data:JSON.stringify(self.menu),
                    contentType:"application/json",
                    dataType:"json",
                    success:function (date) {
                        self.menu.menuState = -1;
                        console.log(date);
                        alert(date.info);
                        //刷新
                        self.loadData();
                    }
                })
            },
            //删除
            deleteData:function (data) {
                var flag = confirm("确定要删除吗？");
                var self = this;
                if(flag){
                    self.menu = data;
                    $.ajax({
                        url:"http://192.168.7.36:2021/login-caipinguanli/menu/deleteRedis",
                        type:"post",
                        data:JSON.stringify(self.menu),
                        contentType:"application/json",
                        dataType:"json",
                        success:function (data) {
                            alert(data.info);
                            if(data.info=="保存成功"){
                                self.menu.menuState = -1;
                                //刷新
                                self.loadData();
                            }
                        }
                    })
                }
            }
        },
        mounted() {
            //运行loadData函数
            this.loadData();

        }
    })

</script>
</html>
